import logging

import requests

from config import BASE_HOST


class RelName:

    def __init__(self,sess):
        self.sess=sess
    #实名认证
    def relname_api(self,phone,name,cardid):

        #先登录获取cookie
        url = BASE_HOST + "/member/public/login"
        form_dict = {"keywords":phone,"password":"qqq123"}
        resp = self.sess.post(url=url, data=form_dict)

        logging.info(f"---------------登录用户为{phone}-------------------登录响应数据为{resp.json()}")

        ##实名认证
        relname_url= BASE_HOST + "/member/realname/approverealname"
        mul_data={'realname': name,'card_id': cardid}
        res2=self.sess.post(url=relname_url,data=mul_data,files={"x":"y"})
        logging.info(f"---------------------------------实名认证的响应结果是{res2.json()}")
        print(res2.json())
        return res2
    #获取认证信息
    def getapprove(self,phone):

        #先登录获取cookie
        url = BASE_HOST + "/member/public/login"
        form_dict = {"keywords":phone,"password":"qqq123"}
        self.sess.post(url=url, data=form_dict)
        getapprove_url=BASE_HOST + "/member/member/getapprove"
        getapp_res=self.sess.post(url=getapprove_url)
        print(getapp_res.json())
        return getapp_res

    # 开户，返回第三方开户信息
    def reguser(self,phone):
        url = BASE_HOST + "/member/public/login"
        form_dict = {"keywords": phone, "password": "qqq123"}
        resp = self.sess.post(url=url, data=form_dict)

        logging.info(f"---------------登录用户为{phone}-------------------登录响应数据为{resp.json()}")
        reg_url = BASE_HOST + "/trust/trust/register"
        res=self.sess.post(url=reg_url)
        print(res.json())
        return res
    # 第三方开户接口
    def third_open_account(self, url, form_dict):
        resp = self.sess.post(url=url, data=form_dict)
        # 将响应体的数据打印到日志
        logging.info("第三方开户接口返回的响应体数据：{}".format(resp.text))
        # 封装方法的返回
        return resp
